package com.wang.controller.api;

import com.wang.bo.PayBo;
import com.wang.entity.User;
import com.wang.service.PayService;
import com.wang.utils.ConstantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Classname ApiPayController
 * @Description TODO
 * @Date 2025/3/25 9:50
 * @Created by pc
 */
@RestController
@Slf4j
@RequestMapping("/api/pay")
public class ApiPayController {
    @Resource
    private PayService payService;

    @PostMapping(value = "/confirm",produces = {"text/html;charset=utf-8"})
    public Object pay(PayBo payBo, HttpSession session) throws Exception {
        User loginUser = (User) session.getAttribute(ConstantUtil.LOGIN_USER);
        payBo.setUserId(loginUser.getId());
        return payService.pay(payBo);
    }

    @PostMapping("/notify")
    public void notify(HttpServletRequest request){
        Map<String, String[]> map = request.getParameterMap();
        // map.forEach((k,v)->{
        //     System.out.println("-----------------"+k+"----------------");
        //     for (String s : v) {
        //         System.out.println(s);
        //     }
        // });
        payService.updatePayStatus(map);
    }


}
